const app = getApp()

Page({
    data: {
        hidden: !0,
        address: {}
    },
    onLoad:function(option) {
      
        /*console.log(option)
        this.setData({
            ret: option.ret
        })*/
    },
  onShow: function (options) {
      var that = this
      //页面初始化，option为页面跳转所带来的参数
      let openid = wx.getStorageSync("openid");
      //var openid = options.openid
      console.log("openid", openid)
      wx.request({
        url: app.globalData.baseUrl +'/userinfo/getuserinfobyopenid',
        method: 'GET',
        data: { "buyerOpenid": openid },//传入的参数
        success: function (res) {
          var list = res.data.userAddressinfo;
          if (list == null) {
            var toastText = '获取数据失败' + res.data.errMsg;
            wx.showToast({
              title: toastText,
              icon: '',
              duration: 2000
            });
          } else {
            that.setData({
              userAddressinfo: list
            });
          }
        }
      })
  },
   addAddress: function () {
    wx.navigateTo({
      url: '../../address/edit/index',
    })
  },
  backtoindex: function (e) {
    var pages = getCurrentPages();
    let currPage = pages[pages.length - 1];   //当前页面
    let prevPage = pages[pages.length - 2];  //上一个页面
    prevPage.setData({
      mydata: { 
        addressId: e.currentTarget.dataset.addressid,
        addressInfo: e.currentTarget.dataset.addressInfo,
        addressBuyerAddress: e.currentTarget.dataset.addressBuyerAddress
        }
    })
    console.log("地址信息", addressId + addressInfo + addressBuyerAddress)
    wx.navigateBack({
      delta: 1 //想要返回的层级
    })
  }
  
   ,
    radioChange(e) {
        /*console.log('radio发生change事件，携带value值为：', e.detail.value)
        App.WxService.redirectTo('/pages/order/confirm/index', {
            id: e.detail.value
        })*/
    },
    getAddressList() {
        /*const address = this.data.address
        const params = address.params

        this.setData({ 
            hidden: !1
        })

        App.HttpService.getAddressList(params)
        .then(data => {
            console.log(data)
            if (data.meta.code == 0) {
                address.items = address.items.concat(data.data.items)
                address.paginate = data.data.paginate
                address.params.page = data.data.paginate.next
                address.params.limit = data.data.paginate.perPage

                address.items.forEach((n, i) => n.checked = n._id === this.data.ret)

                this.setData({
                    address: address
                })
            }

            this.setData({ 
                hidden: !0
            })
        })*/
    },
    onPullDownRefresh() {
        this.initData()
        this.getAddressList()
    },
    onReachBottom() {
        this.lower()
    },
    lower() {
        if (!this.data.address.paginate.hasNext) return
        this.getAddressList()
    },
})